<?php require_once("includes/initializeSession.php"); ?>
<?php
   if (!isset($_SESSION['person_number'])) {
       header('Location: agentLogin.php');
   }
   ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
   <title>ר.א צ'ק אין - פתרונות ביטוח</title>
   <head>
      <?php require_once("includes/cssAndJs.php"); ?>
      <script type="text/javascript">
         //style="vertical-align:top"
         var get_Mehiron_Names_With_PricesJson;
         //var edit_ahlafa=0;
         $(document).ready(function() {
             
         $("#clientGrid").hide();
         
             
             //-- key enter for searching client id
                 $("#clientId").keypress(function (e) {
                 if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                     $('#imgBTN').click();
                     return false;
                 } else {
                     return true;
                 }
             });
             //--end  key enter for searching client id
             
               var payment_type = {
                 "מזומן": "מזומן",
                 "אשראי": "אשראי",
                 "העברת בנקאית": "העברת בנקאית",
                 "צ'קים": "צ'קים"}
         
             // calander stuff
             var person_number_trigger = 0;
             var checkInDate;
             var checkOutDate;
             var checkDate;
             function setStartDateForEndDate() {
                 var temp = checkInDate.datepicker('getDate');
                 if (temp)
                     return {minDate: temp};
                 else
                     return {};
         
             }
             function setEndDateForStartDate() {
         
                 var temp = checkOutDate.datepicker('getDate');
                 if (temp)
                     return {maxDate: temp};
                 else
                     return {};
         
             }
             function refreshPrice() {
                 
                  // var manuyPriceForYear=$(this).val();
                  
                           var manuyPriceForYear=get_Mehiron_Names_With_PricesJson.prices[$("#product_desc").val()];
                             if (Date.parse($("#from_2").val()).add(6).month().compareTo(Date.parse($("#until").val())) === -1 || $("#state").val()=="החלפה")
                             {
                                  //jqgridFormMassage("יותר מחצי שנה")
                                 var a = Date.parse($("#from_2").val()).add(1).year();
                                 var b = Date.parse($("#from_2").val());
                                 var c =Date.parse($("#until").val());
                                 var manuyDuration = new TimeSpan(c - b);
                                 var daysInYear = new TimeSpan(a - b);
                                 
                                 
                                 var price =manuyPriceForYear / 365 * (manuyDuration.days);
                                 /*
                                 if (manuyDuration.days<355)
                                 price += 5;
                                */
                                 price=Math.ceil(price);
                                 $("#product_price").val(price);
                                 $("#total_payment").val(price);
                                
                             }
                             else
                             {
                                 //jqgridFormMassage("פחות מחצי שנה")
                                 $("#product_price").val(manuyPriceForYear/2);
                                 $("#total_payment").val(manuyPriceForYear/2);
                             }
                              $("#agent_commission").val("0");
                /* var startDate = checkInDate.datepicker('getDate');
                 var EndDate = checkOutDate.datepicker('getDate');
                 if (startDate > EndDate)
                     checkOutDate.val('');*/
             }
             
             function refreshPriceOמSwipe() {
                 
                         var manuyPriceForYear=get_Mehiron_Names_With_PricesJson.prices[$("#product_desc").val()];
                         var amlaPrice = parseInt(getSelectedCellManuim("agent_commission"));
                         var a = Date.parse(getSelectedCellManuim("from_2"));
                         var d = Date.parse(getSelectedCellManuim("until"));
                         var b = Date.parse($("#from_2").val());
                         var c =Date.parse($("#until").val());
                         var manuyDuration = new TimeSpan(c - b);
                         var OrginalDuration = new TimeSpan(d - a);
                         
                        console.log(amlaPrice)
                        console.log(OrginalDuration.days)
                        console.log(manuyDuration.days)
                        if (manuyDuration.days!=0)
                            {
                        var AmlaYahasit =amlaPrice / OrginalDuration.days * (manuyDuration.days);
                        var manuyPriceYahasit =manuyPriceForYear / 365 * (manuyDuration.days);
                        manuyPriceYahasit=Math.ceil(manuyPriceYahasit);
                        AmlaYahasit=Math.ceil(AmlaYahasit);
                            }
                            else
                                {
                         var AmlaYahasit =0
                        var manuyPriceYahasit =0  
                                }
                        
                        console.log(manuyPriceYahasit)
                        console.log(AmlaYahasit)
                        
                        $("#product_price").val(manuyPriceYahasit);
                        $("#agent_commission").val(AmlaYahasit);
                        $("#total_payment").val(manuyPriceYahasit + AmlaYahasit);
                                
                            
             }
             // end calander stuff
         
         
             $("#clientList").jqGrid({
                 url: "gridFunctions/personActions.php",
                 editurl: "gridFunctions/personActions.php",
                 direction: 'rtl',
                 async: false,
                 datatype: 'json',
                 pager: '#clientPager',
                 colNames: ['מספר לקוח', 'ת"ז', 'שם פרטי', 'שם משפחה', 'מייל', 'עיר', 'רחוב ובית', 'טלפון', 'פקס', 'פלאפון'],
                 colModel: [
                     {name: 'person_number', index: 'person_number', width: 160, editable: false, align: 'right'},
                     {name: 'person_id', index: 'person_id', width: 60, editable: true, align: 'right' },
                     {name: 'firstname', index: 'firstname', width: 120, editable: true, align: 'right' },
                     {name: 'lastname', index: 'lastname', width: 120, editable: true, align: 'right' },
                     {name: 'email', index: 'email', width: 120, editable: true, align: 'right' },
                     {name: 'city', index: 'city', width: 70, editable: true, align: 'right' },
                     {name: 'address', index: 'address', width: 70, editable: true, align: 'right' },
                     {name: 'telephone', index: 'telephone', width: 160, editable: true, align: 'right' },
                     {name: 'fax', index: 'fax', width: 160, editable: true, align: 'right' },
                     {name: 'cellphone', index: 'cellphone', width: 160, editable: true, align: 'right'}],
                 rowNum: 20,
                 rowList: [5, 10, 20, 50],
                 sortname: 'person_number',
                 sortorder: "desc",
                 mtype: "POST",
                 //loadonce: true,
                 postData: {oper: 'view'},
                 viewrecords: true,
                 imgpath: '../../Scripts/css/Aristo/images',
                 autowidth: true,
                 height: "100%"
             }); // -- end of   $("#list").jqGrid({
             $("#clientList").jqGrid('navGrid', '#clientPager', {edit: false, add: false, del: false, refresh: false, closeAfterAdd: true, reloadAfterSubmit: true, search: false},
             // Edit dialog parameters
             {
                 reloadAfterSubmit: true,
                 closeAfterEdit: true,
                 //editData: {person_number: function() {  return "7"; } },
                 beforeShowForm: function() {
                     $('#person_id').attr('readonly', true);
                 },
                 onclickSubmit: function(rp_ge, postdata)
                 {
                     return {person_number: getSelectedCell('person_number')};
                 },
                 afterSubmit: function(response, postdata)
                 {
                     if (response.responseText == "ok")
                     {
                         success = true;
                         alert("פרטי הלקוח התעדכנו בהצלחה")
                     }
                     else
                     {
         
                         success = false;
                         alert("פרטי הלקוח לא התעדכנו בהצלחה")
                     }
                     return [success, response.responseText]
                 }
             },
             // Add dialog parameters
             {
                 reloadAfterSubmit: true,
                 closeAfterAdd: true,
                 id:"addClientBTN",
                 beforeShowForm: function() {
                     $('#person_id').attr('readonly', false);
                 },
                 afterSubmit: function(response, postdata) {
                     if (response.responseText == "ok")
                     {
                         success = true;
                         alert("לקוח התווסף בהצלחה")
                         $('#imgBTN').click();
                     }
                     else
                     {
                         success = false;
                         alert("לקוח לא התווסף בהצלחה")
                     }
                     return [success, response.responseText]
                 }
         
             },
             // Delete dialog parameters
             {
                 reloadAfterSubmit: true,
                 onclickSubmit: function(rp_ge, postdata)
                 {
                     return {person_number: getSelectedCell('person_number')};
                 },
                 afterSubmit: function(response, postdata) {
                     if (response.responseText == "ok")
                     {
                         success = true;
                         alert("לקוח נמחק בהצלחה")
                     }
                     else
                     {
                         success = false;
                         alert("לקוח לא נמחק בהצלחה")
                     }
                     return [success, response.responseText]
                 }
         
             },
             // Search dialog parameters
             {},
             // View dialog parameters
             {}
             );
             $('#clientList').jqGrid('filterToolbar', {searchOnEnter: true, enableClear: false});
         
                     //---------manuim jq grid
                     
         var mygrids=new Array("15","15_45","45_60","60");
         var minRange=new Array("0","15","45","60");
         var maxRange=new Array("15","45","60","99999");
         for (var i = 0; i < 4; i++) {
       
         

                     $("#manuimList"+ mygrids[i]).jqGrid({
                         url: "gridFunctions/manuimActions.php",
                         editurl: "gridFunctions/manuimActions.php",
                         direction: 'rtl',
                         async: false,
                         datatype: 'json',
                         loadError: function(xhr, st, err) {
                             $($("[id=gs_person_number]")[1]).attr("disabled", "disabled")
                         },
                         loadComplete: function() {
         
                             // 	alert("Sdf");
                             $($("[id=gs_person_number]")[1]).attr("disabled", "disabled")
                  
                         },
                         pager: '#manuimPager'+ mygrids[i],
                         name:mygrids[i],

                         colNames: ['מספר שורה', 'מספר מנוי', 'תאריך אסמכתא', 'מצב', 'סוכן', 'לקוח', 'מתאריך', 'עד תאריך', 'סוג רכב', 'קוד דגם', 'מס רישוי', 'שנת ייצור', 'סוג מנוי', 'מחיר מנוי', 'באמצעות', 'עמלת סוכן', 'ע"ח עמלה', 'עלות למבוטח', 'שולם?', 'אחרון', 'תשלום לסוכן', 'שולם ס.מ', 'אושר'],
                         colModel: [
                             {name: 'manuy_row', hidden: true, index: 'manuy_row', width: 60, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                             {name: 'manuy_number', index: 'manuy_number', width: 100, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                             {name: 'create_2', index: 'create_2', width: 190, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                             {name: 'state', index: 'state', width: 60, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                             {name: 'agent_person_number', index: 'agent_person_number', width: 60, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                             {name: 'person_number', index: 'person_number', width: 120, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                             {name: 'from_2', index: 'from_2', width: 110, editable: true, align: 'right'},
                             {name: 'until', index: 'until', width: 110, editable: true, align: 'right'},
                             {name: 'manufacturer', index: 'manufacturer', width: 70, editable: true, align: 'right'},
                             {name: 'model', index: 'model', width: 70, editable: true, align: 'right'},
                             {name: 'license_plate', index: 'license_plate', width: 80, editable: true, align: 'right'},
                             {name: 'production_year', index: 'production_year', width: 80, editable: true, align: 'right'},
                             {name: 'product_desc', index: 'product_desc', width: 200, editable: true, edittype: "select",
             editoptions: {
                 dataEvents: [
                     {
                         type: 'change',
                         fn: function(e) {
                          
                       refreshPrice();
                         }
                     }
                 ]
             }
         },
                             {name: 'product_price', editoptions: {readonly: "readonly"}, index: 'product_price', width: 80, editable: true, align: 'right'},
                             {name: 'paymen_type', index: 'paymen_type', width: 90, editable: true, align: 'right', edittype: "select", editoptions: {value: payment_type}},
                             {name: 'agent_commission', index: 'agent_commission', width: 90, editable: true, align: 'right', editoptions: {readonly: "readonly"}},
                             {name: 'from_agent_commission', index: 'from_agent_commission', width: 90, editable: true, align: 'right', edittype: 'checkbox', formatter: "checkbox", editoptions: {value: "1:0"}},
                             {name: 'total_payment', index: 'total_payment', width: 60, editable: true, align: 'right',
                                 editoptions: {
                                     dataEvents: [
                                         {
                                             type: 'change',
                                             fn: function(e) {
         
                                                 $("#agent_commission").val($("#total_payment").val() - $("#product_price").val());
         
         
                                             }
                                         }
                                     ]
                                 }
                             },
                             {name: 'shulam', index: 'shulam', width: 60, editable: true, align: 'right', edittype: 'checkbox', formatoptions: {disabled: true}, formatter: "checkbox", editoptions: {value: "1:0"}},
                             {name: 'last', hidden: true, index: 'last', width: 60, editable: true, align: 'right', edittype: 'checkbox',formatoptions: {disabled: true}, formatter: "checkbox", editoptions: {value: "1:0"}},
                             {name: 'shulamToAgent', index: 'shulamToAgent', width: 110, editable: true, align: 'right', edittype: 'checkbox',formatoptions: {disabled: true}, formatter: "checkbox", editoptions: {value: "1:0"}},
                             {name: 'shulamToMertiaAgent', index: 'shulamToMertiaAgent', width: 90, editable: true, align: 'right', edittype: 'checkbox', formatoptions: {disabled: true}, formatter: "checkbox", editoptions: {value: "1:0"}},
                             {name: 'notification_approved', index: 'notification_approved', width: 90, editable: true, align: 'right', edittype: 'checkbox', formatoptions: {disabled: true}, formatter: "checkbox", editoptions: {value: "1:0"}}
                     ],
                     
                                                  onSelectRow: function(rowid) {
                    
                        $(this.id).setGridParam({'postData': {person_number: getSelectedCellManuim("person_number",this.id)}});
                   //  $($("[id=gs_person_number]")[0]).val(getSelectedCellManuim("person_number",this.id));
         searchPersonInGrid(getSelectedCellManuim("person_number",this.id))
         $("#clientGrid").show();
                   //  jQuery("#clientList").trigger('reloadGrid');
                             
                         },
                         rowNum: 20,
                         rowList: [5, 10, 20, 50],
                         sortname: 'person_number',
                         sortorder: "desc",
                         mtype: "POST",
                         //loadonce: true,
                         postData: {oper: 'viewManuimof15DaysPast',minRange: minRange[i],maxRange: maxRange[i]},         
         
                         
                         viewrecords: true,
                         imgpath: '../../Scripts/css/Aristo/images',
                       //  autowidth: true,
                         height: "100%"
                     }); // -- end of   $("#list").jqGrid({
         
         
                     $("#manuimList"+ mygrids[i]).jqGrid('navGrid', '#manuimPager'+ mygrids[i], { edit: false, add: false, del: false, refresh: true, closeAfterAdd: true, reloadAfterSubmit: true, search: false},
                     // Edit dialog parameters
                     {
                        
                     },
                     // Add dialog parameters
                     {
                      
                     },
                     // Delete dialog parameters
                     {
                       
                     },
                     // Search dialog parameters
                     {
                       
                     },
                     // View dialog parameters
                     {}
                     ).navButtonAdd('#manuimPager'+ mygrids[i], {
                         caption: "ביטול",
                         id: "cancelBTN",
                         buttonicon: "ui-icon-add",
                         onClickButton: function() {
                     var grid_id=this.id
                             if (!getSelectedCellManuim("person_number",this.id))
                             {
                                 alert("אתה חייב לבחור מנוי שאותו ברצונך לבטל");
                             }
                             else if (getSelectedCellManuim("state",this.id) != "פעיל")
                             {
                                 alert("אפשר לבטל רק מנוי פעיל");
                             }
                             else if (getSelectedCellManuim("state",this.id) == "פעיל")
                             {
                              openManuimGridDialog(false,false,"add",false,false,this.id); // לא מעניין אותנו לשלוח את החלק שבוזבז
         
                      $("#from_2").val(Date.today().toString('yyyy-MM-dd'));
                                 $.ajax({url: 'gridFunctions/manuimActions.php', // הוצאת התאריך היצירה הראשוני
                                     data: {oper: 'getFirstCreateDate', manuy_number: getSelectedCellManuim("manuy_number",this.id)},
                                     type: 'post',
                                     success: function(output)
                                     {
                                         if (Date.today().compareTo(Date.parse(output).add(15).day()) === -1)
                                         { 
                                            jqgridFormMassage("לא עברו 15 ימים מ " + output + " ולכן המנוי מתבטל ללא תשלום");
                                             $("#total_payment").val(parseInt(getSelectedCellManuim("total_payment",grid_id)) * (-1));
                                             $("#agent_commission").val(parseInt(getSelectedCellManuim("agent_commission",grid_id)) * (-1));
                                         }
                                         else
                                         {
                                            /*
                                              אם יש החזר
                                      ההחזר קודם כל יורד מהעמלות של הסוכן
                                         כאשר הסוכן על 0 העמלות יורדות מאיתנו
         
                                          אם ההחזר גדול מהעמלה יורדת כל העמלה
                                      אם הוא קטן מהעמלה יורד ההחזר
         if( returnMoney*(-1)> parseInt(getSelectedCellManuim("agent_commission")) )
                                         $("#agent_commission").val(parseInt(getSelectedCellManuim("agent_commission")* (-1)));
                                         else
                                             $("#agent_commission").val(returnMoney);   
                                         }
                                       */
                                         var moneyWaste= getMoneyWaste(grid_id);
                                         var manuyMoneyWaste = moneyWaste['manuyMoneyWaste']; //החלק שבוזבז על מנת לדעת כמה נשאר
                                         var agentAmlotMoneyWaste = moneyWaste['agentAmlotMoneyWaste']; //החלק שבוזבז מהעמלה על מנת לדעת כמה נשאר
                                        
                                         var returnMoneyOnManuy =(parseInt(getSelectedCellManuim("total_payment",grid_id)) - manuyMoneyWaste)* (-1);
                                         var returnMoneyOnAmla =(parseInt(getSelectedCellManuim("agent_commission",grid_id)) - agentAmlotMoneyWaste)* (-1);
                                         jqgridFormMassage("עברו 15 ימים ולכן הלקוח נדרש לשלם את החלק היחסי מהתקופה שעברה");
                                         $("#total_payment").val(returnMoneyOnManuy);
                                         $("#agent_commission").val(returnMoneyOnAmla);   
                                     }
                                     }
                                 });	//end og ajax call
          
                                 $("#state").val("מבוטל");
                                 disableAllManuiamFormFields();
                             }
                         },
                         position: "last"
                   
                 }).navButtonAdd('#manuimPager'+ mygrids[i], {
                         caption: "מאשר",
                         buttonicon: "ui-icon-add",
                         onClickButton: function() {
                             if (!getSelectedCellManuim("person_number",this.id))
                             {
                                 alert("אתה חייב לבחור מנוי שברצונך לבצע בו אישור");
                             }
                             else
                             {
                                 openManuimGridDialog(false,false,"approve",false,false,this.id)
                                 jqgridFormMassage("אם אינך מאשר המנוי חשוב כמבוטל , במידה ואתה מאשר נדרש תשלום  בהתאם לתקופה");
                                 disableAllManuiamFormFields();
                                 $("#notification_approved").attr('checked', true);
                                 
                                 
         
                             }
                         },
                         position: "last"
                 
               
                     });
                       
                     // put product_desc in the form dialog
                      $.ajax({url: 'gridFunctions/manuimActions.php',
                     data: {oper: 'get_Mehiron_Names_With_Prices',mehiron_number: "<?php echo  $_SESSION['mehiron_number']; ?>" },
                     type: 'post',
                     success: function(output)
                     {
                         /*	output = output.substr(0, output.length-1); 
                          output = output.substr(1);
                          output=output.replace(/{/g,"");
                          output=output.replace(/}/g,"");
                          output='{"0":"עצמאי",'+output+"}";*/
                         //console.log(output);
                       
                          get_Mehiron_Names_With_PricesJson=eval('(' + output + ')');		   
                         $("#manuimList15").setColProp('product_desc', {editoptions: {value: get_Mehiron_Names_With_PricesJson.names}});
                         $("#manuimList15_45").setColProp('product_desc', {editoptions: {value: get_Mehiron_Names_With_PricesJson.names}});
                         $("#manuimList45_60").setColProp('product_desc', {editoptions: {value: get_Mehiron_Names_With_PricesJson.names}});
                         $("#manuimList60").setColProp('product_desc', {editoptions: {value: get_Mehiron_Names_With_PricesJson.names}});
                        
                     }
                 });
                 
         }
         
         
         
         
         //------------------------------------datepicker for manuim search
                         
                         
                         
                         
                         
                         
                    var  checkInDateInManuimSearch = $($("[id=gs_from_2]")[0]);
                        var     checkOutDateInManuimSearch = $($("[id=gs_until]")[0]);
                             checkInDateInManuimSearch.datepicker({
                                 dateFormat: 'yy-mm-dd',
                             });
         
                             checkOutDateInManuimSearch.datepicker({
                                 dateFormat: 'yy-mm-dd',
                             });
                             checkInDateInManuimSearch.datepicker('setDate', new Date().add(-1).year());
                             checkOutDateInManuimSearch.datepicker('setDate', new Date().add(1).year());
                             
      
          function swapElements(elm1, elm2) {
         var parent1, next1,
         parent2, next2;
         
         parent1 = elm1.parentNode;
         next1   = elm1.nextSibling;
         parent2 = elm2.parentNode;
         next2   = elm2.nextSibling;
         
         parent1.insertBefore(elm2, next1);
         parent2.insertBefore(elm1, next2);
         }
                 /*               
                    swapElements($("#manuimPager_left")[0], $("#manuimPager_right")[0]);
         swapElements($("#clientPager_left")[0], $("#clientPager_right")[0]);
         
         */

                     //-----------------------------------
                  //   $("#clientGrid").hide();
                         });// -- end of  $(document).ready(function ()
                         var b = 3;
                        
                 function getSelectedCell(str)
                 {
                     var grid = jQuery('#clientList');
                     var sel_id = grid.jqGrid('getGridParam', 'selrow');
                     var myCellData = grid.jqGrid('getCell', sel_id, str);
                     return myCellData;
                 }
                 function getSelectedCellManuim(str,mygrid)
                 {
                     var grid = jQuery('#'+ mygrid);
                     var sel_id = grid.jqGrid('getGridParam', 'selrow');
                     var myCellData = grid.jqGrid('getCell', sel_id, str);
                     return myCellData;
                 }
         
         
                 function enableBTN()
                 {
                     $("#cancelBTN").removeClass('ui-state-disabled'); //Enable 
                     $("#freezeBTN").removeClass('ui-state-disabled'); //Enable 
                     $("#unFreezeBTN").removeClass('ui-state-disabled'); //Enable 
                     $("#reNewBTN").removeClass('ui-state-disabled'); //Enable 
                     $("#changeBTN").removeClass('ui-state-disabled'); //Enable 
                 }
         
                 function disableBTN()
                 {
                     $("#cancelBTN").addClass('ui-state-disabled'); //Enable 
                     $("#freezeBTN").addClass('ui-state-disabled'); //Enable 
                     $("#unFreezeBTN").addClass('ui-state-disabled'); //Enable 
                     $("#reNewBTN").addClass('ui-state-disabled'); //Enable 
                     $("#changeBTN").addClass('ui-state-disabled'); //Enable 
         
                 }
         
                 function openManuimGridDialog(manuyMoneyWaste,agentAmlotMoneyWaste,operType,refreshPriceOמSwipe,buttonAction,mygrid)
                 {
                      var amlaPriceBeforeChange = null;
            var totalPriceBeforeChange = null;
            var manuyPriceBeforeChange = null;
            
            manuyMoneyWaste = typeof manuyMoneyWaste !== 'undefined' ? manuyMoneyWaste : false;
            agentAmlotMoneyWaste = typeof agentAmlotMoneyWaste !== 'undefined' ? agentAmlotMoneyWaste : false;
            operType = typeof operType !== 'undefined' ? operType : "add";
            
                   
                     
                     var grid = jQuery("#"+mygrid);
                     var rowKey = grid.getGridParam("selrow");
                     grid.editGridRow(rowKey, {reloadAfterSubmit: true, closeAfterEdit: true, closeAfterAdd: true, recreateForm: true, width: 450,afterShowForm: function() {
                        

                         }, onclickSubmit: function(rp_ge, postdata) 
                         {
                             return {product_desc: $("#product_desc option:selected").text(), manuy_row: getSelectedCellManuim('manuy_row',mygrid), oper: operType,manuyPriceBeforeChange: manuyPriceBeforeChange,amlaPriceBeforeChange:amlaPriceBeforeChange,totalPriceBeforeChange:totalPriceBeforeChange};
                           //  return {product_desc: $("#product_desc option:selected").text(), manuy_row: getSelectedCellManuim('manuy_row'), oper: operType,manuyMoneyWaste: manuyMoneyWaste, agentAmlotMoneyWaste: agentAmlotMoneyWaste, totalPaymentBefore: getSelectedCellManuim("total_payment"), totalComistionBefore: getSelectedCellManuim("agent_commission")};
                         }});
                     $(".navButton").hide();
                     $("#license_plate").mask("99-999-99");
                     
         
                 }
         
                 function getMoneyWaste(mygrid)
                 {
                  var a = Date.today();
                 var b = Date.parse(getSelectedCellManuim("from_2",mygrid));
                 var c = Date.parse(getSelectedCellManuim("until",mygrid));
                 var manuyDuration = new TimeSpan(c - b);
                 var daysPast = new TimeSpan(a - b);
                 var manuyMoneyWaste= parseInt(getSelectedCellManuim("total_payment",mygrid)) / (manuyDuration.days) * (daysPast.days);
                 var agentAmlotMoneyWaste= parseInt(getSelectedCellManuim("agent_commission",mygrid)) / (manuyDuration.days) * (daysPast.days);
                  return {manuyMoneyWaste:manuyMoneyWaste,agentAmlotMoneyWaste:agentAmlotMoneyWaste}
                 }
         
         
                 function jqgridFormMassage(str)
                 {
                     $(".tinfo").show();
                     $(".topinfo").addClass("ui-state-highlight ui-corner-all");
                     $(".topinfo").html(str);
                 }
                 function getFirstCreateDate()
                 {
                     //  var firstDate=false;
                     return   $.ajax({url: 'gridFunctions/manuimActions.php',
                         data: {oper: 'getFirstCreateDate', manuy_number: getSelectedCellManuim("manuy_number")},
                         type: 'post',
                         success: function(output)
                         {
                             //       console.log("output " + output);
                             //    firstDate=output;
                             // console.log(output)
                             return output.responseText;
         
                         }
                     });	//end og ajax call
                     //   console.log("firstDate " + firstDate);
         
                     //   return firstDate;
                 }
                 
                 
                 
                 function searchPersonInGrid(personId)
                 {
                     $($("[id=gs_person_number]")[0]).val(personId);
                     var sgrid = $("#clientList")[0];
                     sgrid.triggerToolbar();
                     
                     
                     
                     
                     
                 }
                 
                 function disableAllManuiamFormFields()
                 {
                    // $("#from_2").val(Date.today().toString('yyyy-MM-dd'));
                     $("#from_2").attr("disabled", true)
                     $("#until").attr("disabled", true)
                     $("#manufacturer").attr("disabled", true)
                     $("#model").attr("disabled", true)
                     $("#license_plate").attr("disabled", true)
                     $("#production_year").attr("disabled", true)
                     $("#total_payment").attr("disabled", true)
                     $("#product_desc").attr("disabled", true)
                     $("#paymen_type").attr("disabled", true)
                     $("#from_agent_commission").attr("disabled", true);
                     $("#shulam").attr("disabled", true);
                     $("#shulamToAgent").attr("disabled", true);
                     $("#shulamToMertiaAgent").attr("disabled", true);
                     $("#notification_approved").attr("disabled", true);
                     
         
                 }
                 var exsitVar=false;
                 function findOrAddClient()
                 {
                      if($("#clientId").val()!="")
                          {
                         exsitVar= $.ajax({url: 'gridFunctions/personActions.php',
                                data: {oper: 'personExsit', person_id: $("#clientId").val()},
                                type: 'post',
                                async: false,
                                success: function(output)
                                {
                                    //       console.log("output " + output);
                                    //    firstDate=output;
                                    // console.log(output)
                                    if (output=="false")
                                        {  
                                        $("#addClientBTN").click();
                                        $("#person_id").val($("#clientId").val());
                                        $("#manuimContainer").hide();
                                        
                                        }
                                    else
                                        {
                                        searchPersonInGrid(output) ;
                                        $("#manuimContainer").show();
                                        }
                                    return output;
         
                                }
                            });	//end og ajax call
                          }
                     
                     
                     //alert(exsitVar.responseText);
         
                 }
         
         
         
      </script>
   </head>
   <body dir="rtl"  style="padding:0px; margin:0px;">
      <div id="main" >
         <?php include("header.php"); ?>
         <div style="margin-top: 20px; text-align: center;">

            <h1>התראות עד 15 יום</h1>
            <div id="lc">
               <table id="manuimList15" class="scroll" cellpadding="0" cellspacing="0"></table>
               <div id="manuimPager15" class="scroll" style="text-align: center;"> </div>
            </div>
            <h1>התראות בין 15 ל 45 יום</h1>
            <div id="lc">
               <table id="manuimList15_45" class="scroll" cellpadding="0" cellspacing="0"></table>
               <div id="manuimPager15_45" class="scroll" style="text-align: center;"> </div>
            </div>
            <h1>התראות בין 45 ל 60 יום</h1>
            <div id="lc">
               <table id="manuimList45_60" class="scroll" cellpadding="0" cellspacing="0"></table>
               <div id="manuimPager45_60" class="scroll" style="text-align: center;"> </div>
            </div>
             <h1>התראות מעל ל60 יום</h1>
            <div id="lc">
               <table id="manuimList60" class="scroll" cellpadding="0" cellspacing="0"></table>
               <div id="manuimPager60" class="scroll" style="text-align: center;"> </div>
            </div>
             
            <div id="clientGrid" >
               <h1> פרטי לקוח </h1>
               <table id="clientList" class="scroll" cellpadding="0" cellspacing="0"></table>
               <div id="clientPager" class="scroll" style="text-align: center;"> </div>
            </div>
         </div>
         <?php include("footer.php"); ?>	
      </div>
   </body>
</html>